package com.china08.yxyapi.api.manage.sch.platform.website.section;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSection;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSectionRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class SectionUpdOrderNumController extends YxyApiBaseController {

    @Autowired
    SwsSectionRepository swsSectionRepository;

    @ApiOperation("创建栏目")
    @RequestMapping(value = "/api_yw/manage/sch/platform/website/section/upd/orderNum", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        // 当前用户学校
        String id = reqModel.id;
        Integer orderNum = reqModel.orderNum;

        SwsSection swsSection = swsSectionRepository.findById(id);
        Assert.isTrue(null != swsSection, "");

        swsSection.setOrderNum(orderNum);
        swsSectionRepository.save(swsSection);
        return true;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        public String id;
        public Integer orderNum;

        @Override
        public void autoCheck() {
            Assert.isTrue(StringUtils.isNotBlank(id), "未获取到修改的数据");
            Assert.isTrue(orderNum > 0 && orderNum < 21, "请输入1-20之间的整数");
        }
    }

    protected static class RespModel extends YxyApiRespModel {
    }
}
